'use strict';
const fs = require("fs");
module.exports = (request, response, rfun)=>{
	if(request.method == "POST"){
		let pd = null;
		request.on("data", (chunk)=>{
			if(Buffer.isBuffer(chunk))
			{
				if(pd) pd = Buffer.concat([pd, chunk], pd.length + chunk.length);
				else pd = chunk;
			}
			else
			{
				if(!pd) pd = '';
				pd += chunk;
			}
		});
		request.on('end', ()=>{
			let fn = "./upfile/tmp";
			if("f" in request.GET.query) fn = "./upfile/" + request.GET.query['f'];
			fs.writeFile(fn, pd, ()=>{
				response.end("ok");
				rfun()
			});
		});
	}else{
		response.end("ok");
		rfun();
	}
}